<!DOCTYPE html>
<html>
<head>
    <meta name="format-detection" content="telephone=no">
    <meta name="msapplication-tap-highlight" content="no">
    <meta name="viewport"
          content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <title>Hello World</title>
</head>
<body>
<div class="app">

    <br><br>

    <!-- 添加用于显示指纹的 img 标签 -->
    <img id="fingerprintImage" src="" alt="Fingerprint Image"
         style="display:none; width:256px; height:360px;"/>
    <br><br>
    <button onclick="powerOn()">power on click</button>
    <br><br>
    <button onclick="powerOff()">power off click</button>
    <br><br>
    <button onclick="init()">init click</button>
    <br><br>
    <button onclick="openDev()">open click</button>
    <br><br>
    <button onclick="closeDev()">close click</button>
    <br><br>
    <button onclick="calibration()">calibration click</button>
    <br><br>
    <button onclick="collect()">collect click</button>
    <br><br>
    <button onclick="continuousCollect()">continuousCollect click</button>
    <br><br>
    <button onclick="stopContinuousCollect()">stopContinuousCollect click</button>
    <br><br>

</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script>

    function test(){
        xyz.aaa("AAA",function(msg){
            alert('原生返回了：'+msg);
        },function(e){
            alert(e);
        })
    }

    function powerOn(){
        alert('开始给USB指纹上电');
        xyz.powerOn("powerOn",function(msg){
            alert('上电成功，请在3秒后进行初始化');
        },function(e){
            alert(e);
        })
    }

    function powerOff(){
        xyz.powerOff("powerOff",function(msg){
            alert('下电成功');
        },function(e){
            alert(e);
        })
    }

    function init(){
        xyz.init("init",function(msg){
            alert('初始化成功，请注意可能弹出的USB权限对话框');
        },function(e){
            alert(e);
        })
    }

    function openDev(){
        xyz.openDev("openDev",function(msg){
            alert('打开指纹模块成功，请注意不要重复打开!');
        },function(e){
            alert(e);
        })
    }

    function closeDev(){
        xyz.closeDev("closeDev",function(msg){
            alert('关闭成功，需进行下电，请注意不要重复打开');
        },function(e){
            alert(e);
        })
    }

    function calibration(){
    alert('正在校准中，请稍候');
        xyz.calibration("calibration",function(msg){
            alert('模块校准结束');
        },function(e){
            alert(e);
        })
    }

    function collect(){
    alert('请把手指按到指纹传感器，点击此选项');
        xyz.collect("collect",function(msg){

            // 假设 msg 包含指纹图像的 Base64 数据
            document.getElementById('fingerprintImage').src = 'data:image/bmp;base64,' + msg; // 设置 img 的 src
            document.getElementById('fingerprintImage').style.display = 'block'; // 显示图像
        },function(e){
            alert(e);
        })
    }

    function continuousCollect(){
    alert('开始连续采集，请按手指到传感器');
        xyz.continuousCollect("continuousCollect",function(msg){
        //alert('原生返回了：'+msg);
             // 假设 msg 包含指纹图像的 Base64 数据
            document.getElementById('fingerprintImage').src = 'data:image/bmp;base64,' + msg; // 设置 img 的 src
            document.getElementById('fingerprintImage').style.display = 'block'; // 显示图像
        },function(e){
            alert(e);
        })
    }

    function stopContinuousCollect(){

        xyz.stopContinuousCollect("stopContinuousCollect",function(msg){
            alert('停止连续获取指纹信息');
        },function(e){
            alert(e);
        })
    }
</script>
</body>
</html>